import Vue from 'vue'	//引入vue
import VueRouter from 'vue-router'	//引入vue-router模块
// 引入进度条组件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })

Vue.use(VueRouter)	//声明安装路由
const routes  =   [
  {name:'首页',path:'/',redirect: '/index'},
  {name:'首页',path:"/index",component:()=> import ('@/pages/index/index'),},//主页
	{name:'demo',path:"/demo",component:()=> import ('@/pages/demo/demo'),},//主页
]
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
// 添加路由守卫
router.beforeEach((to, from, next) => {
  document.title  = to.name ? to.name : 'vue-demo'
  NProgress.start();
  next()
})
// 后置路由守卫
router.afterEach((to, from) => {
  NProgress.done();
})

export default  router